package com.Vronsky;

import com.Vronsky.core.connection.Connection;
import com.Vronsky.core.dataSource.SimpleDataSource;
import com.Vronsky.core.factory.SimpleDataSourceFactory;

import java.sql.SQLException;

public class Test01 {
    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        SimpleDataSource simpleDataSource = SimpleDataSourceFactory.getSimpleDataSource();
        Connection conn1 = simpleDataSource.getConn();
        Connection conn2 = simpleDataSource.getConn();
        Connection conn3 = simpleDataSource.getConn();
        Connection conn4 = simpleDataSource.getConn();
        new Thread("thread-0"){
            @Override
            public void run() {
                SimpleDataSource simpleDataSource = SimpleDataSourceFactory.getSimpleDataSource();
                try {
                    Connection conn5 = simpleDataSource.getConn();
                    Thread.sleep(1000);
                    conn5.close();
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                } catch (ClassNotFoundException e) {
                    throw new RuntimeException(e);
                }
            }
        }.start();

        new Thread("thread-1"){
            @Override
            public void run() {
                SimpleDataSource simpleDataSource = SimpleDataSourceFactory.getSimpleDataSource();
                try {
                    Connection conn6 = simpleDataSource.getConn();
                    System.out.println(conn6);
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }
            }
        }.start();
//        Connection conn5 = simpleDataSource.getConn();
//        Connection conn6 = simpleDataSource.getConn();
//        Connection conn7 = simpleDataSource.getConn();
//        Connection conn8 = simpleDataSource.getConn();
//        Connection conn9 = simpleDataSource.getConn();
//        Connection conn10 = simpleDataSource.getConn();
//        Connection conn11 = simpleDataSource.getConn();
    }
}
